'''
Created on Aug 11, 2009
@author: mjbommar
'''

from tfaces.collection.TimeSeriesExperiment import *
import sys, getopt

def usage():
    '''
    Print the script help usage.
    '''
    print '''loadTimeSeries.py
Run: python loadTimeSeries.py
Arguments:
    -h, --help: print this help usage
    
    -d, --directory: specify the root of the experiment directory to load
        Default = ./ 
        
    -p, --pattern: specify the report file pattern as a regular expression
        Default = report.[0-9]+
        
    -o, --outfile: specify the output database file name
        Default = experiment.db
    '''
    sys.exit(-1)

if __name__ == "__main__":
    opts, args = getopt.getopt(sys.argv[1:], 'hd:p:o:', ["help", "directory=", "pattern=", "outputfile="])                                            
    
    if len(opts) == 0:
        usage()
    
    directory = './'
    pattern = 'report.[0-9]+'
    outfile = 'experiment.db'
    
    for opt, arg in opts:
        if opt in ['-d', '--directory']:
            directory = arg
        elif opt in ['-p', '--pattern']:
            pattern = arg
        elif opt in ['-o', '--outpufile']:
            outfile = arg
        else:
            usage()
    
    d = TimeSeriesExperiment(experimentDirectory = directory, reportFilePattern = pattern)
    d.save(outfile)
    print 'Succesfully loaded.'
    print d